import {HttpStatus} from "./http-status.enum";

// @Catch(HttpException)
export class HttpException extends Error {
    private readonly response: string | Object;
    private readonly status: HttpStatus;

    constructor(response: string | Object, status: HttpStatus) {
        super();
        this.response = response
        this.status = status
    }

    getResponse() {
        return this.response;
    }

    getStatus() {
        return this.status;
    }
}

// 内置异常。。。很多这里列举两个
export class BadRequestException extends HttpException {
    constructor(message, error?) {
        super({message, error, statusCode: HttpStatus.BAD_REQUEST}, HttpStatus.BAD_REQUEST);
    }
}
export class NotFoundException extends HttpException {
    constructor(message, error?) {
        super({message, error, statusCode: HttpStatus.NOT_FOUND}, HttpStatus.NOT_FOUND);
    }
}

export class ForbiddenException extends HttpException {
    constructor(message, error?) {
        super({message, error, statusCode: HttpStatus.FORBIDDEN}, HttpStatus.FORBIDDEN);
    }
}
